home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: findAdjacent.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:32 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include <stdio.h>
- #include "ess.h"
- #include "checking.h"
- #include "list.h"
- #include "io.h"
- #include "tid.h"
- #include "object.h"
- #include "bf.h"
- #include "chunk.h"
- #include "lgobject.h"
- #include "pool.h"
- #include "trace.h"
- #include "error.h"
- #include "version_graph.h"
- #include "version_funcs.h"
- #include "lg_extfuncs.h"
- #include "sm_macro.h"
-
- /*
- * FindAdjacent returns a list of the root nodes of all versions
- * adjacent to a version. Adjacent means all direct children and
- * the parent of the version. This definition also extends
- * recursively to tombstoned versions. For example a tombstone
- * child actually represents all the direct children of the tombstone.
- * Also, a tombstone parent represents all the direct children of
- * all tombstone ancestors up to a non-tombstone ancestor.
- */
-
-
- int
- findAdjacent(
- BUFGROUP *bufGroup,
- VERSIONGRAPH *graph, /* graph containing node */
- VHGNODEID nodeId, /* node to mark pending */
- LIST *adjList, /* list of adjacent versions */
- POOL *adjListPool /* pool for adj list nodes */
- )
- {
- VHGNODE* node;
- VHGNODEID parentId;
- VHGNODEID childId;
- LGNODELIST *adjVersion;
- BOOL found;
-
- TRPRINT(TR_VERSION, TR_LEVEL_1, ("finding adjacent to node %d \n", nodeId) );
-
- CHECK_VERSIONGRAPH_MAGIC(graph);
-
- /*
- * Validate nodeId
- */
- if (nodeId >= graph->nodeCount) {
- SM_ERROR(TYPE_WARNING, esmINTERNAL);
- return esmFAILURE;
- }
-
- /*
- * Get a pointer to the node
- */
- node = &graph->nodeArray[nodeId];
-
- /*
- * Do some defensive error checking. The node should be frozen
- */
- CHECK_VHGNODE_MAGIC(node);
- SM_ASSERT(LEVEL_3, (node->flags & V_frozen));
-
- /*
- * The first half of the search is to determine the "parents" of
- * the version. This involves searching up the VHG searching
- * for the first non-tombstone parent. For each tombstone parent
- * found, all its direct parents are considered "parents" of
- * the version.
- */
- parentId = node->parentId;
- childId = nodeId;
- found = FALSE;
- while (parentId != VHGNULLNODE && !found) {
-
- /*
- * See if the parent is a tombstone
- */
- if (graph->nodeArray[parentId].flags & V_tombstone) {
-
- /*
- * Add the children of the parent to the list
- */
- findDirectChildren(bufGroup, graph, parentId, childId,
- adjList, adjListPool);
-
- /*
- * advance up to the next parent
- */
- childId = parentId;
- parentId = graph->nodeArray[parentId].parentId;
-
- } else {
-
- /*
- * A non-tombstone parent was found, so add it
- * to the list
- */
-
- /*
- * First get a list element and initialize it
- */
- if ((adjVersion = (LGNODELIST *) poolDeq( adjListPool )) == NULL) {
- /*
- * set the error code and return
- */
- SM_ERROR(TYPE_WARNING, esmNOFREELGNODELIST);
- return(esmFAILURE);
- }
- if (lg_GetRootNodePid(bufGroup,
- &graph->nodeArray[parentId].oid,
- &adjVersion->pid, &adjVersion->slot) ) {
- return(esmFAILURE);
- }
-
- /*
- * Add it to the list, and stop the search
- */
- listEnq(adjList, &adjVersion->list);
- found = TRUE;
- }
- }
-
- /*
- * The second half of the search is to find the direct children
- * of the version.
- */
- findDirectChildren(bufGroup, graph, nodeId, VHGNULLNODE, adjList,
- adjListPool);
-
- return(esmNOERROR);
- }
-